﻿using System;
using Newtonsoft.Json.Linq;

namespace Wala.Connection.Objects.Authen
{
    public class LoginServer
    {
        #region //--------- Private Fields -----------//

        private string _host;        
        private int _port;       

        #endregion

        #region //--------- CLR Properties -----------//

        public string Host
        {
            get { return _host; }
            set { _host = value; }
        }

        public int Port
        {
            get { return _port; }
            set { _port = value; }
        }

        #endregion

        #region //---------- Puclic Constructor -----------//

        public LoginServer()
        {
            _host = "";
            _port = 0;
        }

        public LoginServer(string _host, int _port)
        {
            this._port = _port;
            this._host = _host;
        }

        #endregion

        #region //----------- Public Methods ----------//

        public static LoginServer FromJson(string json)
        {
            try
            {
                JObject jObject = JObject.Parse(json);
                string host = (string)jObject["host"];
                int port = (int)jObject["port"];

                return new LoginServer(host, port);
            }
            catch (Exception ex)
            {
                return new LoginServer();
            }
        }

        #endregion
    }
}
